package org.ph.share.lock.test.thread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * Thread 测试类
 *
 * @author Hush.
 * @since 2023/5/15 9:53
 */
@Slf4j
public class ThreadTest3 {
   private static int i1 = 0;
   private static int i2 = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread("t1") {
            @Override
            public void run() {

                log.info("test join 1");
                try {
                    TimeUnit.SECONDS.sleep(3);
                    i1 += 10;
                } catch (InterruptedException e) {
                    log.error("test join catch ", e);
                    throw new RuntimeException(e);
                } finally {
                    log.info("test  finally ");
                }
                log.info("test  run");

            }
        };
        Thread thread2 = new Thread("t2") {
            @Override
            public void run() {

                log.info("test join 1");
                try {
                    TimeUnit.SECONDS.sleep(5);
                    i2 += 10;
                } catch (InterruptedException e) {
                    log.error("test join catch ", e);
                    throw new RuntimeException(e);
                } finally {
                    log.info("test  finally ");
                }
                log.info("test  run");

            }
        };
        
        thread1.start();
        thread2.start();

        thread1.join();
        thread2.join(1000);
        log.info("test int:{},{}", i1,i2);

    }
}
